import BaseView from "./baseView.js";

export default class Login extends BaseView{

    render(){
        this.app.html(
           ` <div style='margin:50px auto;width:600px'>
           <form class="layui-form">
           <div class="layui-form-item">
             <label class="layui-form-label">用户名:</label>
             <div class="layui-input-inline">
               <input type="text" id="username" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
             </div>
           </div>
           <div class="layui-form-item">
             <label class="layui-form-label">密&nbsp;&nbsp;码</label>
             <div class="layui-input-inline">
               <input type="password" id="pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
             </div>
           </div>
           
           <div class="layui-form-item">
             <div class="layui-input-block">
               <button type="button" id="loginBtn" class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
               <button type="reset" class="layui-btn layui-btn-primary">重置</button>
             </div>
           </div>
         </form>
           </div>`
        )

        
    }

    hander(){
        $("#loginBtn").click(()=>{
            $.ajax({
              type:"get",
              url:'/user/login/'+$('#username').val()+'/'+$('#pwd').val(),
              dataType:"json",
              success:(data)=>{
                //console.log(data);
                if(data.code==0){
                   alert(data.msg);
                   location.href="#/main"
                }else{
                  alert(data.msg);
                }
              }
           }
            )
        })
  }
}

